package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    List<User> getUsers(UserDto userDto);

    /* 实体类

     * */
    @Insert("insert into user(username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time) " +
            "values(#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void addUser(User user);

    void deleteUsers(List<Integer> ids);

    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user where id=#{id}")
    User getUserById(Integer id);

    void updateUser(User user);

    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user")
    List<User> listUsers();

    List<User> listUsersByRoleLabel(String roleLabel);

    List<User> listUsersByDeptId(Integer deptId);

    @Select("SELECT u.*, r.label as role_label FROM user u LEFT JOIN role r ON u.role_id = r.id WHERE u.username = #{username}")
    User getUserByUsername(String username);
}
